package com.pmsystem.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pmsystem.dao.KeyRecordMapper;
import com.pmsystem.pojo.KeyRecord;
import com.pmsystem.util.BeanUtil;

@Service
public class KeyRecordService {

	@Autowired
	private KeyRecordMapper keyRecordMapper;

	/**
	 * 
	 * <p>Title: addKeyRecord</p >  
	 * <p>Description: 添加借钥匙记录</p >  
	 * @author 泽强
	 * @param keyRecord
	 * @return
	 */
	public boolean addKeyRecord(KeyRecord keyRecord) {
		int flag = keyRecordMapper.insertSelective(keyRecord);
		return flag==1?true:false;
	}

	/**
	 * 
	 * <p>Title: updateKeyRecord</p >  
	 * <p>Description: 修改借钥匙记录</p >  
	 * @author 泽强
	 * @param keyRecord
	 * @return
	 */
	public boolean updateKeyRecord(KeyRecord keyRecord) {
		int flag = keyRecordMapper.updateByPrimaryKeySelective(keyRecord);
		return flag==1?true:false;
	}

	/**
	 * 
	 * <p>Title: findKeyRecord</p >  
	 * <p>Description: 按一定条件查询借钥匙记录</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	public List<KeyRecord> findKeyRecord(Map<String, Object> map) {
		Integer pageNo = (Integer) map.get("pageNo");
		Integer pageSize = (Integer) map.get("pageSize");
		if(pageNo!=null&&pageSize!=null) {
			int start = (pageNo - 1) * pageSize;
			map.put("start", start);
		}
		return keyRecordMapper.findKeyRecord(BeanUtil.mapToMapWithoutNull(map));
	}
	
	
}
